package com.shushan.pages.newtype.bean;

import com.android.net.bean.NetBaseBean;

import org.json.JSONArray;
import org.json.JSONException;
import org.json.JSONObject;

import java.util.ArrayList;
import java.util.List;

/**
 * @ClassName: EnglishWordsEntryItemBean
 * @Desciption: //单词练习入口页单词item数据bean
 * @author: zhangshihao
 * @date: 2018-07-31
 */
public class EnglishWordsEntryItemBean extends NetBaseBean {

    public String new_word;
    public int id;
    public String english_name;
    public String chinese_name;
    public String pronunciation;//读音
    public String voice;

    private List<InterpretationBean> interpretationBeans = new ArrayList<>();
    private List<ExampleSentenceBean> exampleSentenceBeans = new ArrayList<>();

    @Override
    public void initByJson(JSONObject jsonObject) throws JSONException {
        if(jsonObject == null){
            return;
        }
        new_word = jsonObject.optString("new_word","");
        id = jsonObject.optInt("id",0);
        english_name = jsonObject.optString("english_name","");
        chinese_name = jsonObject.optString("chinese_name","");
        pronunciation = jsonObject.optString("pronunciation","");
        voice = jsonObject.optString("voice","");

        JSONArray interArr = jsonObject.optJSONArray("interpretation");
        if(interArr != null && interArr.length() > 0) {
            for (int i=0;i<interArr.length();i++) {
                JSONObject interObj = interArr.optJSONObject(i);
                InterpretationBean bean = new InterpretationBean();
                bean.initByJson(interObj);
                interpretationBeans.add(bean);
            }
        }
        JSONArray sentenceArr = jsonObject.optJSONArray("example_sentence");
        if(sentenceArr != null && sentenceArr.length() > 0){
            for(int i=0;i<sentenceArr.length();i++){
                JSONObject sentenceObj = sentenceArr.optJSONObject(i);
                ExampleSentenceBean sentenceBean = new ExampleSentenceBean();
                sentenceBean.initByJson(sentenceObj);
                exampleSentenceBeans.add(sentenceBean);
            }
        }
    }

    public List<ExampleSentenceBean> getExampleSentenceBeans() {
        return exampleSentenceBeans;
    }

    public List<InterpretationBean> getInterpretationBeans() {
        return interpretationBeans;
    }

}
